package com.huishu.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huishu.commons.pojo.Result;
import com.huishu.user.pojo.dto.PopupDTO;
import com.huishu.user.pojo.model.PopupDO;
import com.huishu.user.service.PopupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @author generator@ljj
* @since 2023-04-22
*/
@RestController
@RequestMapping("/popup")
public class PopupController {

    @Autowired
    private PopupService popupService;

    @PostMapping("/create")
    public Result create(@RequestBody PopupDTO popupDTO){
        return popupService.create(popupDTO);
    }

    @PostMapping("/update")
    public Result modify(@RequestBody PopupDTO popupDTO){
        return popupService.modify(popupDTO);
    }

    @GetMapping ("/findAll")
    public Result findAll(){
        LambdaQueryWrapper<PopupDO> queryWrapper = Wrappers.lambdaQuery(PopupDO.class)
                .orderByDesc(PopupDO::getCreatedDate);
        return Result.success(popupService.list(queryWrapper));
    }
}
